package com.gzhryc.shared_device.oem.code.device.services;

import java.sql.SQLException;
import java.util.List;

import com.gzhryc.common.logging.Logger;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.MultiDBTools;
import com.gzhryc.shared_device.oem.code.device.dao.AgentRelationBXSCNBatteryDao;
import com.gzhryc.shared_device.oem.code.device.dao.models.AgentRelationBXSCNBattery;
import com.gzhryc.shared_device.oem.code.device.services.dto.AgentRelationBXSCNBatterySearch;

public class AgentRelationBXSCNBatteryService {
	
	static Logger log = Logger.getLogger(AgentRelationBXSCNBatteryService.class);

    public static AgentRelationBXSCNBatteryService self() {
        return MultiDBTools.getService(AgentRelationBXSCNBatteryService.class, true);
    }

    public static AgentRelationBXSCNBatteryService self(String jdbcKey) {
        return MultiDBTools.getService(jdbcKey, AgentRelationBXSCNBatteryService.class, true);
    }

    AgentRelationBXSCNBatteryDao dao;

    public AgentRelationBXSCNBatteryService(String jdbcKey) {
        dao = new AgentRelationBXSCNBatteryDao(jdbcKey);
    }

    public List<AgentRelationBXSCNBattery> findJoinBySearch(AgentRelationBXSCNBatterySearch search,Integer pageNo,Integer pageLimit){
    	Conditions condition = dao.buildConditions(search);

    	try {
			return dao.findJoinByCondition(condition, pageNo, pageLimit);
		} catch (SQLException e) {
			log.error(e.getMessage(), e);
		}
    	return null;
    }
    
    public Long countJoinBySearch(AgentRelationBXSCNBatterySearch search) {
    	Conditions condition = dao.buildConditions(search);

    	try {
			return dao.countJoin(condition);
		} catch (SQLException e) {
			log.error(e.getMessage(), e);
		}
    	return 0L;
    }
}
